home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 60.zip
/
BS1 part 60
/
C mon v3 d3.adf
/
CMANV3_3.LHA
/
ACE9.lha
/
Devices
/
TimerDevice
/
Example3.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-27
|
4KB
|
137 lines
/***********************************************************/
/* */
/* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
/* ------------------------------- ------------------ */
/* */
/* Book: ACM Devices Amiga C Club */
/* Chapter: Timer Device Tulevagen 22 */
/* File: Example3.c 181 41 LIDINGO */
/* Author: Anders Bjerin SWEDEN */
/* Date: 92-04-27 */
/* Version: 1.00 */
/* */
/* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
/* */
/* Registered members may use this program freely in their */
/* own commercial/noncommercial programs/articles. */
/* */
/***********************************************************/
/* This example demonstrates how you can use the Timer Device */
/* to get the current system time. We will then add two hours */
/* and set the new system time. */
#include <exec/types.h> /* STRPTR */
#include <exec/ports.h> /* struct Message */
#include <exec/memory.h> /* MEMF_PUBLIC */
#include <devices/timer.h> /* TIMERNAME */
/* The reply port: */
struct MsgPort *replymp;
/* The timer request block: */
struct timerequest *tr;
/* When the Timer Device is open this variable is TRUE: */
BOOL not_opened = TRUE;
/* Declare our functions: */
void clean_up();
void main();
void main()
{
/* Get a reply port: */
replymp = (struct MsgPort *)
CreatePort( NULL, 0 );
if( !replymp )
clean_up( "Could not create the reply port!" );
/* Get an extended request block: */
tr = (struct timerequest *)
CreateExtIO( replymp, sizeof( struct timerequest) );
if( !tr )
clean_up( "Could not create the IO!" );
/* Open the Timer Device: */
not_opened = OpenDevice( TIMERNAME, UNIT_VBLANK, tr ,0 );
if( not_opened )
clean_up( "Could not open the Timer Device!" );
/* We want to get the current system time: */
tr->tr_node.io_Command = TR_GETSYSTIME;
/* Do our request: */
printf( "Let's check the time...\n" );
DoIO( tr );
/* Print the current system time: */
printf( "The current system time is:\n" );
printf( "Seconds: %d\n", tr->tr_time.tv_secs );
printf( "Microseconds: %d\n", tr->tr_time.tv_micro );
/* Note that while Exec has handled your request the system */
/* time has already changed, so the current system time is */
/* not very current (it is already some micro seconds late). */
/* Add two hours: */
tr->tr_time.tv_secs += 60 * 60 * 2;
/* We want to set a new system time: */
tr->tr_node.io_Command = TR_SETSYSTIME;
/* Do our request: */
printf( "Adding two hours to the system time...\n" );
DoIO( tr );
/* Note that you should not set the time backwords. The timer */
/* device has never seen a clock going backwords, so it is best */
/* to not make it or some other program to excited! */
/* Clean up and quit: */
clean_up( "The End!" );
}
void clean_up( text )
STRPTR text;
{
/* Close the Timer Device: */
if( !not_opened )
CloseDevice( tr );
/* Delete the extended request block: */
if( tr )
DeleteExtIO( tr, sizeof( struct timerequest) );
/* Remove the message port: */
if( replymp )
DeletePort( replymp);
/* Print the last message: */
printf( "%s\n", text );
/* Quit: */
exit( 0 );
}